﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Logic;
using Entities;

namespace Application1
{
    public partial class Form2 : Form
    {
        static Division division1 = new Division();
        List<AbstractVegetables> vegetables1;
        AbstractVegetables vegetable;
        Form1 form1;


        //===================================================================================
        public Form2(Form1 fr1, Division division, List<AbstractVegetables> vegetables)
        {
            InitializeComponent();
            form1 = fr1;
            vegetables1 = vegetables;
            division1 = division;
            comboBox1.Items.Add("Помидор");
            comboBox1.Items.Add("Лук");
            comboBox1.Items.Add("Фасоль");
            Label[] labelBox = { label2, label3 };
            TextBox[] textBoxBox = { textBox1, textBox2 };

        
        

        }



                     // Кнопка №2
        //=====================================================================================

        public Form2(Form1 fr1, Division division, List<AbstractVegetables> vegetables, int selectedIndex)
        {
            InitializeComponent();
            this.Text = "Редактирование"; // Имя окна
            form1 = fr1;
            vegetables1 = vegetables;
            division1 = division;

            button1.Visible = true;
            comboBox1.Visible = false;
            label1.Visible = false;

            comboBox1.Items.Add("Помидор");
            comboBox1.Items.Add("Лук");
            comboBox1.Items.Add("Фасоль");

            Label[] labelBox = { label2, label3 };
            TextBox[] textBoxBox = { textBox1, textBox2 };


            vegetable = vegetables[selectedIndex];


            if (vegetable != null)
            {
                textBox1.Text = vegetable.Name;
                textBox2.Text = Convert.ToString(vegetable.Calorificvalue);
            }
        }
        //========================================================================================  


        private void button1_Click(object sender, EventArgs e)
        {
            if (comboBox1.Text == "Помидор")
            {
                AbstractVegetables st1 = new AbstractVegetables();

                st1.Name = comboBox1.Text + "  " + textBox1.Text;
                st1.Calorificvalue = Convert.ToInt32(textBox2.Text);
                division1.AddVegetable(st1);
            }


            if (comboBox1.Text == "Лук")
            {
                AbstractVegetables st2 = new AbstractVegetables();

                st2.Name = comboBox1.Text + "  " + textBox1.Text;
                st2.Calorificvalue = Convert.ToInt32(textBox2.Text);        
                division1.AddVegetable(st2);
            }


            if (comboBox1.Text == "Фасоль")
            {
                AbstractVegetables st3 = new AbstractVegetables();
                st3.Name = comboBox1.Text + "  " + textBox1.Text;
                st3.Calorificvalue = Convert.ToInt32(textBox2.Text);  
                division1.AddVegetable(st3);
            }

           

     
           
            form1.listBox1.Items.Clear();
            foreach (AbstractVegetables vegetable in vegetables1)
            {
                form1.listBox1.Items.Add(vegetable.Name + "  " + vegetable.Calorificvalue);

                form1.UpdateLength();
                Close();
            }
            



        }

        private void button2_Click(object sender, EventArgs e)
        {
            Close();
        }

        
    }
}


        
        
        
        


       
      
    

